package net.cohoivang.web;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Properties;

import net.cohoivang.core.ProfileCompany;
import net.cohoivang.core.TradingManager;
import net.cohoivang.news.NewsManager;

public class GoldenChance {

	private static Properties properties;
	
	public static void initialize() throws IOException {
		loadProperties();
		try {
			Class.forName(properties.getProperty("db_driver"));
			OurConnection.initialize();
			OurConnection connection = openConnection("Goldenchange ...");
			ProfileCompany.initialize(connection);
			NewsManager.initialize(connection);
			TradingManager.initialize(Integer.parseInt(properties.getProperty("topNewsSize")));
		} catch (ClassNotFoundException ex) {
			ex.printStackTrace();
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}
	
	private static void loadProperties() throws IOException {
		properties = GoldenChanceProperties.getInstance().getProperties();
	}
	
	public static String getProperties(String key) {
		return properties.getProperty(key);
	}
	
	public static OurConnection openConnection(String caller) {
		return OurConnection.poolOut(caller);
	}
}
